<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of news
 *
 * @author Administrator
 */
class News extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->model('news_model');
    }
    public function insert(){
        
        $arr=array(
            'id'=>2,
            'title'=>'yangk',
            'slug'=>'yangk,yangk',
            'text'=>'url:yangk'
        );
        $this->news_model->insert_news($arr);
    }
    
    public function update(){

        $id=2;
        $arr=array(
            'title'=>'yangjing',
            'slug'=>'yangk,yangk',
            'text'=>'url:yangk'
        );
        $this->news_model->update_news($id,$arr);
    }
    
    public function delete(){

        $id=1;
        $this->news_model->delete_news($id);
    }
    
    public function select($id){
        $this->load->helper('url');
        
        $news=  $this->news_model->select_news($id);
        //var_dump($news);
        if($news){
            echo $news[0]->id.'-'.$news[0]->title;
        }else{
            redirect('news');
        }
    }

    //put your code here
    public function index(){
        $this->load->helper('url');
        $this->load->library('session');
        if($this->session->userdata['uid']){
            $news=$this->news_model->select_news();
            $data=array('news'=>$news);
            $this->load->view('news_view',$data);
        }else{
            $this->load->helper('url');
            redirect('login');
        }
    }
}
